/*
 * @Author: 宋慧武
 * @Date: 2019-04-14 16:44:42
 * @Last Modified by: 宋慧武
 * @Last Modified time: 2019-07-30 20:17:13
 */
import { Notification, Message } from "element-ui";
import { format } from "../date";
import {indexGet} from '@/api/log'
import Cookies from "js-cookie";

// import { createFragment } from "../utils/dom";

/**
 * @desc 模拟埋点Action
 */
export default function trackAction(evt, addtional = {}) {
  const data = {
    evt,
    ...addtional,
    action_time: format(Date.now())
  };
  if (evt === "1") {
   
     console.log(1,addtional)

     let pageName = addtional.meta.title;
     let path = addtional.path;
     let param = {
       'pageName': pageName,
       'path': path
     }
     if(path=="/"||path=="/booklistdetails"||path=="/booklist")
     indexGet(param)
     .then(res => {
       // console.log(res.data.data.judge === "notHandle")
       if (res.data.data.judge === "notHandle") {

          console.log('已经有notHandle')
       } else {

          console.log(res.data)
         let oiddate = new Date(res.data.data.expires).getTime()
         let newdate = new Date().getTime()
         // console.log(newdate > oiddate)
         // console.log(oiddate , newdate)
         if (res.data.data.judge === 'handle' && newdate < oiddate) {

           // console.log('flag的值为handle  但是当前时间比expires的值小', oiddate)
           // console.log(oiddate , newdate)
           Cookies.set('mydxWebSite', res.data.data.mydxWebSite, {expires: 1})
         }
       }

     })

   // Message("统计UVPV埋点");
  }
  if (evt === "2") {
   
    console.log("2",addtional)
    // Message({
    //   message: "统计页面停留时间埋点",
    //   customClass: "message-offset"
    // });
  }

  // Notifhication.success({
  //   title: "上报数据如下：",
  //   dangerouslyUseHTMLString: true,
  //   message: data,
  //   customClass: "notification__large",
  //   position: evt === "1" || evt === "2" ? "top-left" : "top-right"
  // });
}
